home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Edit a file *)
- (* *)
- (* Copyright (c) 1985, 87 by Borland International, Inc. *)
- (* Copyright 1988, 1989, 1991 by H. Roy Engehausen. All rights reserved. *)
- (* *)
- (* This code cannot be used in other programs except in conjunction *)
- (* with a licensed copy of the Turbo Editor Toolbox *)
- (* *)
- (*===========================================================================*)
-
- {$UNDEF DEBUG_PATH}
- {$UNDEF DEBUG_OVER}
- {$UNDEF DEBUG_BP}
-
- {$O+}
-
- UNIT BBEDIT;
-
- INTERFACE
-
- USES
- bbdummy;
-
- PROCEDURE edit_file_main(cmd_string : STRING);
- PROCEDURE oper_et(cmd_in : STRING);
- PROCEDURE oper_emptr(msg_ptr : msg_index_ptr);
-
- IMPLEMENTATION
-
- USES
- DOS,
- CRT,
- bined,
- bbdump,
- bbedits,
- bbmdata,
- bbmess,
- bbmf,
- bbsdata,
- bbsema2,
- bbstack,
- bbstr,
- bbtask,
- bbwin;
-
- {$I BBEDITSO.PAS}
-
- PROCEDURE edit_file_main(cmd_string : STRING);
-
- VAR
- b : BOOLEAN;
- i : BYTE;
- mem_size : LONGINT;
-
- (*=========================================================================*)
- (* Edit file cleanup *)
- (*=========================================================================*)
-
- PROCEDURE edit_file_leave;
- VAR
- junkroy : BYTE;
- BEGIN;
-
- releasebinaryeditorheap(eddata);
-
- window_select(window_reset);
-
- COLOR(opt_block.status_color);
-
- GOTOXY(1, window_location[window_full_screen].window_wl);
-
- CLREOL;
-
- window_select(window_operator);
-
- CLRSCR;
-
- i := window_cursor_update(1);
-
- window_refresh(window_operator);
-
- edit_window_busy := FALSE;
-
- status_window_change := TRUE;
-
- END;
-
- (*=========================================================================*)
- (* Edit main line starts here *)
- (*=========================================================================*)
-
- BEGIN;
-
- {$IFDEF DEBUG_PATH}
- WRITELN('Edit main line start');
- {$ENDIF}
-
- (*-----------------------------------------------------------------------*)
- (* Check for valid syntax *)
- (*-----------------------------------------------------------------------*)
-
- i := WORDS(cmd_string);
-
- IF i <> 2 THEN
- BEGIN;
- IF i > 2 THEN
- send_message(message_err_wrd)
- ELSE
- send_message(message_not_en);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- fname := subword(@cmd_string, 2, 1);
-
- (*-----------------------------------------------------------------------*)
- (* Compute memory size *)
- (*-----------------------------------------------------------------------*)
-
- mem_size := MAXAVAIL - opt_block.editor_free;;
- IF mem_size < 0 THEN
- BEGIN;
- window_write('ED::', ' Insufficent memory available');
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- IF mem_size > maxfilesize THEN
- mem_size := maxfilesize;
-
- (*-----------------------------------------------------------------------*)
- (* Initialize window info *)
- (*-----------------------------------------------------------------------*)
-
- edit_window_busy := TRUE;
-
- {$IFDEF DEBUG_PATH}
- WRITELN('Window set');
- {$ENDIF}
-
- window_select(window_reset);
-
- windx := get_window_x(window_operator);
- windx1 := HI(windx);
- windx2 := LO(windx);
-
- windy := get_window_y(window_operator);
- windy1 := HI(windy);
- windy2 := LO(windy);
-
- WINDOW(windx1, windy1, windx2, windy2);
-
- CLRSCR;
-
- (*-----------------------------------------------------------------------*)
- (* Initialize editor *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_PATH}
- WRITELN('Init');
- {$ENDIF}
-
- exitcode := initbinaryeditor(
- eddata, (*Editor control block, initialized by InitBinaryEditor*)
- mem_size, (*Size of data area to reserve for binary editor text buffer, $FFE0 max*)
- windx1 + 1, (*Coordinates of editor window, upper left 1..80*)
- windy1 + 1, (*Coordinates of editor window, upper left 1..25*)
- windx2 - 1, (*Coordinates of editor window, lower right*)
- windy2 - 1, (*Coordinates of editor window, lower right*)
- opt_block.opt_direct_snow, (*True to wait for retrace on color cards*)
- edoptinsert+edoptindent, (*Initial editor toggles*)
- '', (*Default extension for file names*)
- myexitcommands, (*Commands to exit editor*)
- ADDR(usereventcheck)); (*Address of user event handler*)
-
- (*-----------------------------------------------------------------------*)
- (* If editor didn't initialize ok then leave *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_PATH}
- WRITELN('Check');
- {$ENDIF}
-
- b := checkinitbinary(exitcode);
- IF b THEN
- BEGIN;
- edit_file_leave;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Obtain the interrupt lock *)
- (*-----------------------------------------------------------------------*)
-
- get_semaphore(semaphore_interrupts, sem_exclusive, FALSE);
-
- (*-----------------------------------------------------------------------*)
- (* Read the file and make sure it worked *)
- (*-----------------------------------------------------------------------*)
-
- exitcode := readfilebinaryeditor(eddata, fname);
- b := checkreadfile(exitcode, filenamebinaryeditor(eddata));
-
- (*-----------------------------------------------------------------------*)
- (* Release the interrupt lock *)
- (*-----------------------------------------------------------------------*)
-
- free_semaphore(semaphore_interrupts);
-
- (*-----------------------------------------------------------------------*)
- (* If errors so far then exit *)
- (*-----------------------------------------------------------------------*)
-
- IF b THEN
- BEGIN;
- edit_file_leave;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Ready editor *)
- (*-----------------------------------------------------------------------*)
-
- resetbinaryeditor(eddata);
-
- {$IFDEF DEBUG_BP}
- WRITELN('BP3');
- DELAY(2000);
- {$ENDIF}
-
- (*-----------------------------------------------------------------------*)
- (* Signal size not updated *)
- (*-----------------------------------------------------------------------*)
-
- edit_size := -1;
-
- (*-----------------------------------------------------------------------*)
- (* Start status line *)
- (*-----------------------------------------------------------------------*)
-
- initstatusline;
-
- (*-----------------------------------------------------------------------*)
- (* Loop while editing *)
- (*-----------------------------------------------------------------------*)
-
- REPEAT
-
- (*---------------------------------------------------------------------*)
- (* Draw the editor window *)
- (*---------------------------------------------------------------------*)
-
- initwindow(eddata);
-
- (*---------------------------------------------------------------------*)
- (* Execute the editor *)
- (*---------------------------------------------------------------------*)
-
- executeeditor;
-
- {$IFDEF DEBUG_OVER}
- WRITELN('X');
- DELAY(2000);
- dump_string('Ready to close');
- dump_overlay;
- dump_trace;
- {$ENDIF}
-
- (*---------------------------------------------------------------------*)
- (* Call exit handler *)
- (*---------------------------------------------------------------------*)
-
- b := exitbinaryeditor(eddata, exitcomcode);
-
- UNTIL b;
-
- (*-----------------------------------------------------------------------*)
- (* Clean up *)
- (*-----------------------------------------------------------------------*)
-
- edit_file_leave;
-
- (*-----------------------------------------------------------------------*)
- (* Tell we are done *)
- (*-----------------------------------------------------------------------*)
-
- IF edit_operation = 0 THEN
- send_message(message_op_complete);
-
- END;
-
- (*===========================================================================*)
- (* Operator edit message text *)
- (*===========================================================================*)
-
- PROCEDURE oper_et(cmd_in : STRING);
-
- VAR
- code : INTEGER;
- e_msg_no : LONGINT;
- i : WORD;
- msg_ptr : msg_index_ptr;
-
- BEGIN;
-
- (*-----------------------------------------------------------------------*)
- (* Check for valid syntax *)
- (*-----------------------------------------------------------------------*)
-
- i := WORDS(cmd_in);
-
- IF i <> 2 THEN
- BEGIN;
- IF i > 2 THEN
- send_message(message_err_wrd)
- ELSE
- send_message(message_not_en);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Convert message number to something reasonable *)
- (*-----------------------------------------------------------------------*)
-
- VAL(subword(@cmd_in, 2, 1), e_msg_no, code);
-
- IF (code <> 0) OR (e_msg_no < 1) OR (e_msg_no > 65535) THEN
- BEGIN;
- send_message(message_err_ivm);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Find the message number *)
- (*-----------------------------------------------------------------------*)
-
- msg_ptr := find_msg(e_msg_no);
-
- IF msg_ptr = NIL THEN
- BEGIN;
- send_message(message_rmc_nf);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Build the edit command *)
- (*-----------------------------------------------------------------------*)
-
- STR(e_msg_no, cmd_in);
- cmd_in := 'EF ' + opt_block.msg_file_dir + 'BB' + cmd_in + '.MSG';
-
- (*-----------------------------------------------------------------------*)
- (* Call edit *)
- (*-----------------------------------------------------------------------*)
-
- edit_file_main(cmd_in);
-
- (*-----------------------------------------------------------------------*)
- (* If size updated, change header *)
- (*-----------------------------------------------------------------------*)
-
- IF edit_size >= 0 THEN
- BEGIN;
- msg_ptr^.msg_i_mb.msg_size := edit_size + 1;
- update_msg(msg_ptr);
- END;
-
- END;
-
- (*===========================================================================*)
- (* Operator edit message text based on a pointer *)
- (*===========================================================================*)
-
- PROCEDURE oper_emptr(msg_ptr : msg_index_ptr);
-
- VAR
- s : STRING;
-
- BEGIN;
-
- (*-----------------------------------------------------------------------*)
- (* Build the edit command *)
- (*-----------------------------------------------------------------------*)
-
- STR(msg_ptr^.msg_i_mb.msg_number, s);
- s := 'EF ' + opt_block.msg_file_dir + 'BB' + s + '.MSG';
-
- (*-----------------------------------------------------------------------*)
- (* Call edit *)
- (*-----------------------------------------------------------------------*)
-
- edit_parm := msg_ptr;
-
- edit_file_main(s);
-
- (*-----------------------------------------------------------------------*)
- (* If size updated, change header *)
- (*-----------------------------------------------------------------------*)
-
- IF edit_size >= 0 THEN
- BEGIN;
- msg_ptr^.msg_i_mb.msg_size := edit_size + 1;
- update_msg(msg_ptr);
- END;
-
- END;
-
- END.